using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AimController : MonoBehaviour
{

    private Camera mainCamera;
    private void Awake()
    {
        mainCamera = Camera.main;
        if (mainCamera == null)
        {
            Debug.LogError("mainCarmera lost!!!");
        }
    }

    private void Update()
    {
        Vector3 position = mainCamera.WorldToScreenPoint(transform.position);
        Vector3 direction = Input.mousePosition - position;
        float angle = Mathf.Atan2(direction.x,direction.y)*Mathf.Rad2Deg;

        transform.rotation = Quaternion.AngleAxis(-angle,Vector3.forward);
    }
}
